package com.ruoyi.audit.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.CashRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.audit.service.ICashRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 提现记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-23
 */
@RestController
@RequestMapping("/record")
public class CashRecordController extends BaseController
{
    @Autowired
    private ICashRecordService cashRecordService;

    /**
     * 查询提现记录列表
     */
    @PreAuthorize(hasPermi = "audit:record:list")
    @GetMapping("/list")
    public TableDataInfo list(CashRecord cashRecord)
    {
        startPage();
        List<CashRecord> list = cashRecordService.selectCashRecordList(cashRecord);
        return getDataTable(list);
    }

    /**
     * 导出提现记录列表
     */
    @PreAuthorize(hasPermi = "audit:record:export")
    @Log(title = "提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CashRecord cashRecord) throws IOException
    {
        List<CashRecord> list = cashRecordService.selectCashRecordList(cashRecord);
        ExcelUtil<CashRecord> util = new ExcelUtil<CashRecord>(CashRecord.class);
        util.exportExcel(response, list, "record");
    }

    /**
     * 获取提现记录详细信息
     */
    @PreAuthorize(hasPermi = "audit:record:query")
    @GetMapping(value = "/{cashid}")
    public AjaxResult getInfo(@PathVariable("cashid") Long cashid)
    {
        return AjaxResult.success(cashRecordService.selectCashRecordById(cashid));
    }

    /**
     * 新增提现记录
     */
    @PreAuthorize(hasPermi = "audit:record:add")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CashRecord cashRecord)
    {
        return toAjax(cashRecordService.insertCashRecord(cashRecord));
    }

    /**
     * 修改提现记录
     */
    @PreAuthorize(hasPermi = "audit:record:edit")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CashRecord cashRecord)
    {
        return toAjax(cashRecordService.updateCashRecord(cashRecord));
    }

    /**
     * 删除提现记录
     */
    @PreAuthorize(hasPermi = "audit:record:remove")
    @Log(title = "提现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cashids}")
    public AjaxResult remove(@PathVariable Long[] cashids)
    {
        return toAjax(cashRecordService.deleteCashRecordByIds(cashids));
    }

}
